package com.songcha.module_category.ui.adapter

import android.graphics.Color
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.songcha.library_common.ui.view.CustomContainerLayout
import com.songcha.library_common.util.GlideUtil
import com.songcha.module_category.R
import com.songcha.module_category.bean.CategoryChannelSubListBean

class CategorySubAdapter(list:MutableList<CategoryChannelSubListBean.ChannelSubBean>):BaseQuickAdapter<CategoryChannelSubListBean.ChannelSubBean,BaseViewHolder>(R.layout.category_item_sub,list) {
    val ITEM_COLORS= listOf(
        "#F2FDE8","#F8F6D6",
        "#FCF3FC","#C7E7FB",
        "#EFF8FB","#EFD6F8",
        "#FCF3FC","#E2C7FB",
        "#E8FAFD","#FCE0AF",
        "#FCF3FC","#C7E7FB"
    )

    override fun convert(holder: BaseViewHolder, item: CategoryChannelSubListBean.ChannelSubBean) {
        holder.getView<CustomContainerLayout>(R.id.category_sub_item_ccl).apply{
            var index=(holder.absoluteAdapterPosition+1)%(ITEM_COLORS.size/2)
            if(index==0)
                index=ITEM_COLORS.size/2
            setStartColor(Color.parseColor(ITEM_COLORS[(index-1)*2]))
            setEndColor(Color.parseColor(ITEM_COLORS[(index-1)*2+1]))
        }

        holder.getView<TextView>(R.id.category_sub_tv_title).apply {
            text=item.catName
        }
        holder.getView<ImageView>(R.id.category_sub_iv_thumb).apply {
            GlideUtil.loadNetImage(this,item.catCover)
        }

    }
}